package com.site.wisdom_construction.controller.iotModule;

import com.alibaba.fastjson.JSONObject;
import com.site.wisdom_construction.responseEntity.JsonResult;
import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.responseEntity.Page;
import com.site.wisdom_construction.service.iotModule.CarWashService;
import com.site.wisdom_construction.util.HttpRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2021/12/21
 * @Description
 */
@Api(tags = "污泥监测接口")
@RestController
@RequestMapping("CarWash")
@CrossOrigin
public class CarWashController {
    @Autowired
    private CarWashService carWashService;

    @ApiOperation(value = "查询最新一条数据", notes = "")
    @PostMapping("/ceshi")
    public void ceshi(@RequestBody Map<String, Object> map) {
        JSONObject jsonObject = new JSONObject();
        HttpRequest httpRequest =new HttpRequest();
        String path = "http://jisuaqi.market.alicloudapi.com/aqi/query?cityid=161";
        jsonObject = httpRequest.Header(path,"");
        System.out.println("jsonObject:"+jsonObject);
    }

    @ApiOperation(value = "数据上传接口" , notes = "传参:")
    @PostMapping("/insertCarWash")
    public boolean insertCarWash(@RequestBody Map map){
        return carWashService.insertCarWash(map)==1;
    }

    @ApiOperation(value = "查询最新一条数据", notes = "")
    @PostMapping("/findCarWashByNew")
    public OneDataResult findCarWashByNew(@RequestBody Map<String, Object> map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(carWashService.findCarWashByNew(map));
        return oneDataResult;
    }

    @ApiOperation(value = "历史车辆监测数据", notes = "")
    @PostMapping("/findCarWashByAll")
    public OneDataResult findCarWashByAll(@RequestBody Map<String, Object> map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(carWashService.findCarWashByAll(map));
        return oneDataResult;
    }

    @ApiOperation(value = "类型统计", notes = "")
    @PostMapping("/countCarWashByAlarmType")
    public OneDataResult countCarWashByAlarmType(@RequestBody Map<String, Object> map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(carWashService.countCarWashByAlarmType(map));
        return oneDataResult;
    }

    @ApiOperation(value = "未冲洗次数较好统计_未冲洗", notes = "")
    @PostMapping("/countCarWashByWCX")
    public OneDataResult countCarWashByWCX(@RequestBody Map<String, Object> map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(carWashService.countCarWashByWCX(map));
        return oneDataResult;
    }

    @ApiOperation(value = "未冲洗次数较好统计_绕行", notes = "")
    @PostMapping("/countCarWashByRX")
    public OneDataResult countCarWashByRX(@RequestBody Map<String, Object> map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(carWashService.countCarWashByRX(map));
        return oneDataResult;
    }

    @ApiOperation(value = "监测统计", notes = "")
    @PostMapping("/countCarWashByJCTJ")
    public OneDataResult countCarWashByJCTJ(@RequestBody Map<String, Object> map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(carWashService.countCarWashByJCTJ(map));
        return oneDataResult;
    }

    @ApiOperation(value = "删除污泥监测数据", notes = "测试数据:")
    @PostMapping("/deleteCarWash")
    public JsonResult deleteCarWash(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        List<Integer> list = (List<Integer>) map.get("list");
        int l = 0;
        Map mapR = new HashMap();
        for (int i = 0;i<list.size();i++){
            mapR.put("id",list.get(i));
            int a = carWashService.deleteCarWash(mapR);
            l+=a;
        }
        if (l>=1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功删除污泥监测数据!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("删除污泥监测数据失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "分页模糊查询污泥监测数据", notes = "测试数据:")
    @PostMapping("/findCarWashByPage")
    public Page findCarWashByPage(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(carWashService.Total(map));
        page.setItems(carWashService.findCarWashByPage(map));
        return page;
    }
}
